import * as types from '../types';
import axios from 'axios';

export default {
  state: {
    data: []
  },
  mutations: {
    [types.SET_SESSIONS]: (state, payload) => {
      state.data = [];
      for (let i = 0; i != payload.length; ++i) {
        state.data.push(payload[i]);
      }
    },
    [types.RESET_APPS]: (state) => {
      state.data = [];
    }
  },
  actions: {
    load_sessions: ({ commit }, payload) => {
      axios.get('/sessions/').then(response => {
        commit(types.SET_SESSIONS, response.data);
      }).catch(err => {
        console.log('error occured.');
        console.log(err);
      });
    }
  }
}